const mySymbol = (()=>{
    const map = new Map()
    function fn(params) {
        if(this instanceof fn){
            return new Error("not new")
        }
    }
    // k-v
    fn.for = function (key) {
        if(!map.has(key)){
            map.set(key,{})
        }
        return map.get(key)
    }
    // v- k
    fn.forOf = function (val) {
        for (const [k,v] of map) {
            if(v== val){
                return k
            }
        }
    }
    return fn // 注意// 注意
})()


// 私有属性
// symbol 
let x = symbol()
class A {
    constructor() {
        this[x] = {}
    }
    getx() {
        return this[x]
    }
}

// 闭包
(() => {
    let _x 
    class A {
        constructor(x) {
            _x = x
        }
        getx() {
            return _x
        }
    }

    return A

})()


// #支持私有变量

// 继承
function Fa(params) {}

function Son(...args) {
    Fa.call(this, ...args)
}
function inherit(son,fa) {
    let newSon = Object.create(fa.prototype)
    son.prototype = newSon;
    son.prototype.constructor = son;
}
inherit(Son, Fa)


Vue.extend = function(extendOptions){
    const Super = this;
    const Sub = function VueComponent(options) {
        this._init(options)
    }

    Sub.prototype = Object.create(Super.prototype);
    Sub.prototype.constructor = Sub;
    Sub['super'] = Super;
    Sub.extend = Super.extend
    return Sub
}  

// 可迭代器， 使原有的object 支持for of 
// for in 支持对象  for of 支持可迭代对象
Object.prototype[Symbol.iterator] = function () {
    let keys = Object.keys(this);
    let index = 0;
    return {
        next: () => {
            return {
                value: this[keys[index++]],
                done: index >= keys.length + 1 ? true : false,
            }
        }
    }
}
